﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace CanvasEx.DrawCore
{
    class DrawRectangle : DrawObject
    {
        Point left_top, left_bottom, right_top, right_bottom;
        RectangleGeometry rectangle;

        public DrawRectangle(Painter p, Point left_top, Point right_bottom)
            : base(p)
        {
            this.left_top = left_top;
            this.left_bottom.X = left_top.X;
            this.left_bottom.Y = right_bottom.Y;
            this.right_top.X = right_bottom.X;
            this.right_top.Y = left_top.Y;
            this.right_bottom = right_bottom;
            rectangle = new RectangleGeometry(new Rect(left_top, right_bottom));
        }
        public override Geometry GetGeometry()
        {
            return rectangle;
        }

        public override bool InGraph(Point Location, double SelectAccuracy)
        {
            if (Location.X < right_top.X + SelectAccuracy && Location.X > left_top.X - SelectAccuracy)
            {
                if (Location.Y < left_top.Y + SelectAccuracy && Location.Y > left_top.Y - SelectAccuracy)
                    return true;
                if (Location.Y < left_bottom.Y + SelectAccuracy && Location.Y > left_bottom.Y - SelectAccuracy)
                    return true;
            }
            if (Location.Y < left_bottom.Y + SelectAccuracy && Location.Y > left_top.Y - SelectAccuracy)
            {
                if (Location.X < left_top.X + SelectAccuracy && Location.X > left_top.X - SelectAccuracy)
                    return true;
                if (Location.X < right_top.X + SelectAccuracy && Location.X > right_top.X - SelectAccuracy)
                    return true;
            }
            return false;

        }
        public override List<Point> GetHotSpot()
        {
            return new List<Point>() { left_top, left_bottom, right_top, right_bottom };
        }

    }
}
